@file:JvmName("CommonUtils")

package com.yl.androidutilscenter.utils

import android.app.Activity
import android.content.Context
import android.os.Build
import android.view.WindowManager
import androidx.core.content.ContextCompat

/**
 * @author
 * @description:
 * @date :2024/3/12
 * @version 1.0.0
 */
object YCommonUtils {

    /**
     * 修改状态栏背景色，针对Android5.0以上
     */
    @JvmStatic
    fun changeStatusColor(activity: Activity, res: Int) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            val window = activity.window
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            window.statusBarColor = ContextCompat.getColor(activity, res)
        }
    }


    //
    fun px2dp(context: Context, pxValue: Int): Int {
        return (pxValue / (context.resources.displayMetrics.density) + 0.5f).toInt()
    }

    fun dp2px(context: Context, dpValue: Int): Int {
        return (dpValue * context.resources.displayMetrics.density + 0.5f).toInt()
    }

    fun px2sp(context: Context, pxValue: Int): Int {
        return (pxValue / context.resources.displayMetrics.scaledDensity + 0.5f).toInt()
    }

    fun sp2px(context: Context, spValue: Int): Int {
        return (spValue * context.resources.displayMetrics.scaledDensity + 0.5f).toInt()
    }



}